package com.innoking.docsys.workflow.controller;

import com.innoking.docsys.utils.JsonToOtherUtil;
import com.innoking.docsys.utils.OtherPojo;
import com.innoking.docsys.utils.ResultObjVO;

import com.innoking.docsys.workflow.module.WorkflowGroupVO;
import com.innoking.docsys.workflow.module.WorkflowUserVO;
import com.innoking.docsys.workflow.service.WorkflowIdentityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 描述:
 *
 * @author zyp
 * @description 工作流身份控制器
 * @create 2019-09-05 11:05
 */
@RestController
@RequestMapping("/workflowIdentity")
public class WorkflowIdentityController {

    Logger logger= LoggerFactory.getLogger(WorkflowModelController.class);

    @Autowired
    WorkflowIdentityService workflowIdentityService;

    /**
     * @author:zyp
     * @description 保存或更新工作流用户
     * @date: 2019/2/27 13:45
     * @param:id:用户id；firstName:用户账号；lastName:用户名；password：密码（可为空）；email:邮箱（可为空）
     * @return
     */
    @PostMapping("/addUpdateUser")
    @ResponseBody
    public ResultObjVO saveUser(@RequestBody String data) {
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new WorkflowUserVO() );
        WorkflowUserVO workflowUser = (WorkflowUserVO)ob.getObj();
        ResultObjVO resultObjVO = workflowIdentityService.addUpdateUser(workflowUser);
        return resultObjVO;
    }

    /**
     * @author:zyp
     * @description 删除工作流用户
     * @date: 2019/9/5 11:45
     * @return 
     */
    @PostMapping("/deleteUser")
    @ResponseBody
    public ResultObjVO deleteUser(@RequestBody String data) {
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new WorkflowUserVO() );
        WorkflowUserVO workflowUserVO = (WorkflowUserVO)ob.getObj();
        ResultObjVO resultObjVO = workflowIdentityService.deleteUser(workflowUserVO.getIds());
        return resultObjVO;
    }

    /**
     * @author:zyp
     * @description 保存Group
     * @date: 2019/9/5 11:48
     * @param：id:组code；name:组名称；type：类型(区分角色或组织——0：角色，1：组织)
     * @return
     */
    @PostMapping(value = "/saveUpdateGroup")
    @ResponseBody
    public ResultObjVO saveUpdateGroup(@RequestBody String data) {
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new WorkflowGroupVO() );
        WorkflowGroupVO workflowGroup = (WorkflowGroupVO)ob.getObj();
        ResultObjVO resultObjVO = workflowIdentityService.saveUpdateGroup(workflowGroup);
        return resultObjVO;
    }

    /**
     * @author:zyp
     * @description 删除组
     * @date: 2019/9/5 13:38
     * @return
     */
    @PostMapping(value = "/deleteGroup")
    public ResultObjVO deleteGroup(@RequestBody String data) {
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new String() );
        String ids = (String)ob.getObj();
        ResultObjVO resultObjVO = workflowIdentityService.deleteGroup(ids);
        return resultObjVO;
    }

}